package com.cater.sys.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.PageResult;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.CompanyOrganizeDao;
import com.cater.sys.entity.CompanyOrganize;

/**
 * 描述：组织架构 服务实现层
 * 
 * @author yong
 * @date 2019/03/07
 */
@Service
public class CompanyOrganizeServiceImpl implements BaseService<CompanyOrganize, CommonQuery, String> {

	@Autowired
	CompanyOrganizeDao dao;

	@Override
	public PageResult<CompanyOrganize> findPageResult(CommonQuery query) {
		PageResult<CompanyOrganize> result = new PageResult<CompanyOrganize>();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<CompanyOrganize> list = dao.findList(query, first, max);
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<CompanyOrganize> getAll() {
		return dao.getAll();
	}

	@Override
	public List<CompanyOrganize> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(CompanyOrganize t) {
		return 0;
	}

	@Override
	public String saves(CompanyOrganize t) {
		t.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		dao.save(t);
		return t.getId();
	}

	@Override
	public void update(CompanyOrganize t) {
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(id);
	}

	@Override
	public CompanyOrganize getById(String id) {
		return dao.getById(id);
	}

	public List<CompanyOrganize> getListBy(CommonQuery query) {
		return dao.getListBy(query);
	}

	public CompanyOrganize getByPid(CommonQuery query) {
		return dao.getByPid(query);
	}
}